package com.nercel.dsj.gksales.util;

import com.github.pagehelper.PageInfo;
import com.nercel.dsj.gksales.exception.ResponseCode;
import com.nercel.dsj.gksales.exception.RestApiException;
import com.nercel.dsj.gksales.model.ListResult;
import com.nercel.dsj.gksales.model.ResponseResult;

/**
 * @author sunlin
 * @date 2018-10-31
 */
public class ApiResultUtil {

    public static ListResult pageList(PageInfo pageInfo) {
        return ListResult.fromPageInfo(pageInfo);
    }

    public static Object notNull(Object object) {
        if (object == null) {
            throw new RestApiException(ResponseCode.NOT_FOUND);
        }
        return object;
    }

    public static ResponseResult success() {
        return new ResponseResult(200, "success", null);
    }

    public static ResponseResult success(String message, Object data) {
        return new ResponseResult(200, message, data);
    }

    public static ResponseResult success(Object data) {
        return new ResponseResult(200, "success", data);
    }


}
